import { baseUrl, get, post, postSafe } from './js/http.js'


/**
 * 登录
 */
export const login = params => post('/user/login', params)

/**
 * 加载字典
 * @param {*} params 
 */
export const loadDict = params => get(`/locale/get.json?lang=zh-CN`, params)

/**
 * 发送验证码
 */
export const sendEcode = params => post('/user/sendEcode', params)

/**
 * 重置验证
 */
export const resetCheck = params => post('/sms/security/resetCheck', params, {
	header: {
		'Content-Type': 'application/json'
	}
})

/**
 * 重置密码
 */
export const resetPwd = params => post('/sms/security/resetPwd', params, {
	header: {
		'Content-Type': 'application/json'
	}
})

/**
 * 手机验证码登录
 */
export const loginBySms = params => post('/user/phoneLogin', params)

/**
 * 字典信息
 */
export const getDicts = params => post('/dict/item/getDictItemsByTypeNames', params)

/**
 * 扫码确认
 */
export const ScanConfim = params => post('/user/scan/confirm', params)


/**
 * 上传
 */
export const uploadFile = ({filePath, name = 'file', formData={}}) => {
	let token = uni.getStorageSync('token')
	return new Promise((resolve) => {
		uni.uploadFile({
		        url: `${baseUrl()}/file/upload`,
		        filePath: filePath,
		        name: name,
		        formData: formData,
				header: {
					'token': token
				},
		        success: (uploadFileRes) => {
		            console.log(uploadFileRes.data);
					resolve(uploadFileRes.data)
		        },
				fail: (err) => {
					 console.log(err);
					resolve()
				}
		    });
	})
}

/**
 * 列表
 * @param  params 
 */
export const SelectListFile = params => post(`/file/selectList`, params)

/**
 * 删除
 * @param  params 
 */
export const DeleteHandleFile = params => post(`/file/delete`, params)

/**
 * 获取 base64
 * @param  params 
 */
export const GetFileBase64 = params => post(`/file/getBase64`, params)

/**
 * 获取配置
 * @param  params 
 */
export const getConfig = params => post(`/setting/getConfig`, params)


/**
 * 保存配置
 * @param  params 
 */
export const SaveConfig = params => postJson(`/setting/saveConfig`, params)

/**
 * 修改密码
 * @param  params 
 */
export const UpdatePwd = params => post(`/user/pwd/update`, params)

/**
 * 分页列表 新闻公告
 * @param  params 
 */
export const SelectPageNotice = params => post(`/article/selectPage`, params)

/**
 * 列表 新闻公告
 * @param  params 
 */
export const SelectListNotice = params => post(`/article/selectList`, params)


/**
 * 获取本机及下级单位编码
 * @param  params 
 */
export const GetSubOrgs = params => post(`/org/getSubOrgs`, params)




/**
 * 发送验证码
 * @param  params 
 */
export const sendReportEcode = params => post(`/work/report/sendEcode`, params)

/**
 * 获取天气信息
 * @param  params 
 */
export const GetWeather = params => post(`/datav/weather`, params)

/**
 * 获取天气信息
 * @param  params 
 */
export const GetWeather2 = params => get(`/datav/water/list2`, params)

/**
 * 获取商品列表
 * @param  params 
 */
export const SelectListProduct = params => post(`/open-api/product/selectList`, params)

/**
 * 获取分类列表
 * @param  params 
 */
export const SelectListCategory = params => post(`/open-api/category/selectList`, params)

/**
 * 下单
 * @param  params 
 */
export const CreateOrder = params => post(`/open-api/order/create`, params, {
	header: {
		'Content-Type': 'application/json'
	}
})

/**
 * 分页订单列表
 * @param  params 
 */
export const SelectPageOrder = params => post(`/open-api/order/selectPage`, params)



/**
 * 分页动态列表
 * @param  params 
 */
export const SelectPageInfo = params => post(`/open-api/info/selectPage`, params)

/**
 * 订单详情列表
 * @param  params 
 */
export const SelectListOrderItem = params => post(`/open-api/order/item/selectList`, params)


/**
 * 订单支付完成
 * @param  params 
 */
export const OrderPay = params => post(`/open-api/order/pay`, params)

/**
 * 订单取消
 * @param  params 
 */
export const OrderCancel = params => post(`/open-api/order/cancel`, params)


/**
 * 获取 openid
 */
export const getOpenid = params => get('/pay/v3/openid', params)

/**
 * 支付
 */
export const payHandle = params => post('/pay/v3/createOrder', params, {
	header: {
		'Content-Type': 'application/json'
	}
})

